import { createSlice, PayloadAction } from '@reduxjs/toolkit'
export type PageInfoType = {
    title: string
    desc?: string
    js?: string
    css?: string
    isPublished?: boolean
}

const INIT_STATE: PageInfoType = {
    title: '',
    desc: '',
    js: '',
    css: '',
}

export const pageInfoSlice = createSlice({
    name: 'pageInfo',
    initialState: INIT_STATE,
    reducers: {
        // 重置页面信息内容
        resetPageInfo: (state: PageInfoType, action: PayloadAction<PageInfoType>) => {
            return action.payload
        },
        // 修改页面标题
        changePageTitle: (state: PageInfoType, action: PayloadAction<string>) => {
            state.title = action.payload
        },
    },
})

export const { resetPageInfo, changePageTitle } = pageInfoSlice.actions
export default pageInfoSlice.reducer
